import React, { useState, useEffect } from 'react';
import moment from 'moment'

import { Table, DatePicker, Select } from 'antd';

import QueryHead from './components/QueryHead/index'

export default function () {
  const columns = [
    {
      title: '起始日期',
      dataIndex: 'startDate',
      key: 'startDate',
      showQueryHead: true,
      defaultItemData:moment().format('YYYY-MM-DD'),
      renderDiyComponents: (dataIndex, changeItemParam) => {
        return (
          <DatePicker
            style={{ width: '100%' }}
            defaultValue={moment()}
            onChange={(val) => {
              let date = moment(val).format('YYYY-MM-DD')
              changeItemParam(date, dataIndex)
            }} />
        );
      }
    },
    {
      title: '结束日期',
      dataIndex: 'endDate',
      key: 'endDate',
      showQueryHead: true,
      renderDiyComponents: (dataIndex, changeItemParam) => {
        return (
          <DatePicker
            style={{ width: '100%' }}
            defaultValue={moment()}
            onChange={(val) => {
              let date = moment(val).format('YYYY-MM-DD')
              changeItemParam(date, dataIndex)
            }} />
        );
      }
    },
    {
      title: '旅客姓名',
      dataIndex: 'name',
      key: 'name',
      showQueryHead: true,
      defaultItemData:'小明'
    },
    {
      title: '旅客年龄',
      dataIndex: 'age',
      key: 'age',
      showQueryHead: true,
      hideInTable:true,
    },
    {
      title: '性别',
      dataIndex: 'sex',
      key: 'sex',
      showQueryHead: true,
      renderDiyComponents: (dataIndex, changeItemParam) => {
        return (
          <Select defaultValue="lucy" onChange={(val) => {
            changeItemParam(val, dataIndex)
          }}>
            <Select.Option value="jack">Jack</Select.Option>
            <Select.Option value="lucy">Lucy</Select.Option>
            <Select.Option value="Yiminghe">yiminghe</Select.Option>
          </Select>
        );
      }
    },
  ];
  const data = [
    {
      key: '1',
      name: 'John Brown',
      age: 32,
      sex: '男',
      address: 'New York No. 1 Lake Park',

    },
    {
      key: '2',
      name: 'Jim Green',
      age: 42,
      sex: '女',
      address: 'London No. 1 Lake Park',
    },
    {
      key: '3',
      name: 'Joe Black',
      age: 32,
      sex: '男',
      address: 'Sidney No. 1 Lake Park',
    },
  ]
  return (
    <>
      <QueryHead tableColumns={columns}></QueryHead>
      <Table columns={columns} dataSource={data} />
    </>
  );
}
